﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using canthovieclam.BL.Models;
using canthovieclam.DAL;
using canthovieclam.DAL.Repositories;

namespace canthovieclam.BL
{
    public class RegisterEmployerImpl
    {
        public bool RegisterEmployer(EmployerModel employerModel, ContactModel contactModel)
        {
            try
            {
                IUnitOfWork unitOfWork = new UnitOfWork();

                var employer = employerModel.MapEmployer(); 
                var employerRepository = new EmployerRepository(unitOfWork);
                employerRepository.AddEmployer(employer);

                Contact contact = contactModel.MapContact(); 
                var contactRepository = new ContactRepository(unitOfWork);
                contactRepository.AddContact(contact);                

                var employerContact = new EmployerContact();
                employerContact.Employer = employer;
                employerContact.ContactTypeId = 1;

                contact.EmployerContact.Add(employerContact);
                unitOfWork.Commit();
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }
    }
}

